package org.ogv;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class CAssetManager extends AssetManager {
	
	public TextureRegion getTextureRegion(String[] path) {
		TextureAtlas ta 	= path.length > 1 ? OGV.asset.get(path[0], TextureAtlas.class) : null;
		return ta == null ? new TextureRegion(OGV.asset.get(path[0], Texture.class)) : ta.findRegion(path[1]);
	}
	
	public void load(AssetDeclaration dcl) {
		if(dcl.textures != null) 
			for(String s : dcl.textures) 		load(s, Texture.class);
		if(dcl.textureAtlases != null) 
			for(String s : dcl.textureAtlases) 	load(s, TextureAtlas.class);
		if(dcl.sounds != null) 
			for(String s : dcl.sounds) 			load(s, Sound.class);
		if(dcl.musics != null) 
			for(String s : dcl.musics) 			load(s, Music.class);
		if(dcl.fonts != null) 
			for(String s : dcl.fonts) 			load(s, BitmapFont.class);
	}
	
	public void unload(AssetDeclaration dcl) {
		if(dcl.textures != null) 
			for(String s : dcl.textures) 		unload(s);
		if(dcl.textureAtlases != null) 
			for(String s : dcl.textureAtlases) 	unload(s);
		if(dcl.sounds != null) 
			for(String s : dcl.sounds) 			unload(s);
		if(dcl.musics != null) 
			for(String s : dcl.musics) 			unload(s);
		if(dcl.fonts != null) 
			for(String s : dcl.fonts) 			unload(s);
	}
	
	public static class AssetDeclaration {
		public String[] textures;
		public String[] textureAtlases;
		public String[] sounds;
		public String[] musics;
		public String[] fonts;
	}
}
